package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CategoryMapper {

    //添加分类数据
    @Insert("insert into category values (null,#{type},#{name},#{sort},#{createTime}," +
            "#{updateTime},#{createUser},#{updateUser})")
    Integer save(Category category);

    //根据类别名查询类别
    @Select("select * from category where name=#{name}")
    Category findByName(String name);

    //分页查询,根据sort排序
    @Select("select * from category order by sort asc")
    List<Category> getAll();

    //删除分类
    @Delete("delete from category where id=#{id}")
    Integer deleteById(Long id);

    //类别修改业务
    Integer update(Category category);

    //根据类别名称查询类别,排除自己
    @Select("select * from category where name=#{name}")
    Category getByName(Category category);

    //根据类型查询类别列表数据
    List<Category> findAllByType(@Param("type") Integer type);

    //分页查询(分表查)
    @Select("select * from category where id=#{id}")
    Category findById(Long id);
}
